﻿#include "widget.h"
#include "ui_widget.h"

#include <QDebug>

#include <fstream>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //combox_1
    ui->comboBox->addItem("麦辣鸡腿堡");
    ui->comboBox->addItem("巨无霸");
    ui->comboBox->addItem("培根蔬萃双层牛堡");

    ui->comboBox_2->addItem("中薯条");
    ui->comboBox_2->addItem("麦乐鸡块");
    ui->comboBox_2->addItem("麦辣鸡翅");

    ui->comboBox_3->addItem("可乐");
    ui->comboBox_3->addItem("雪碧");

    //combox_2
    // 需要读取文件内容, 把文件中的每一行读取出来, 作为一个 ComboBox 的选项
    std::ifstream file("D:/QT_code/qt/Qt_test_24_5_12/config.txt");
    if (!file.is_open()) {
        qDebug() << "open file failed";
        return;
    }
    // 按行来读取文本内容
    // getline 函数完成
    std::string line;
    while (std::getline(file, line)) {
        // 取到的每一行内容, 设置到下拉框中
        ui->comboBox_4->addItem(QString::fromStdString(line));
    }
    file.close();

    //spinBox
    // 针对 QSpinBox 的范围进行设置
    ui->spinBox->setRange(1, 5);
    ui->spinBox_2->setRange(1, 5);
    ui->spinBox_3->setRange(1, 5);

    ui->spinBox->setValue(1);
    ui->spinBox_2->setValue(1);
    ui->spinBox_3->setValue(1);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_submit_clicked()
{
    //qDebug() << ui->comboBox->currentText() << ", " << ui->comboBox_2->currentText() << ", " << ui->comboBox_3->currentText();
    qDebug() << "当前下单的内容: "
                 << ui->comboBox->currentText() << ": " << ui->spinBox->value()
                 << ui->comboBox_2->currentText() << ": " << ui->spinBox_2->value()
                 << ui->comboBox_3->currentText() << ": " << ui->spinBox_3->value();
}
